<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        body {
            margin: 0;
        }

        nav {
            width: 100%;
            height: 50px;
            display: flex;
            position: fixed;
            bottom: 0;
            background-color: #f1f1f1;
        }

        nav div {
            flex: 1;
            text-align: center;
            line-height: 50px;
        }

        .red {
            background-color: red;
            color: #fff;
        }

        .navbar {
            width: 100%;
            height: 50px;
            line-height: 50px;
            color: #fff;
            background-color: #3190e8;
            display: flex;
            justify-content: space-between;
        }
    </style>
</head>

<body>
    <div id="root">

    </div>
</body>
<script src="../react.js"></script>
<script src="../react-dom.js"></script>
<!-- 用来将jsx语法转化为js语法 -->
<script src="../babel.min.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.3/jquery.js"></script>
<script type="text/babel">
    class App extends React.Component {
        state = {
            navList: ['首页', '分类', '购物车', '我的'],
            activeIndex: 0
        }
        render() {
            let { activeIndex } = this.state;
            return (
                <div>
                    {activeIndex === 0 && <Home />}
                    {activeIndex === 1 && <Cate />}
                    {activeIndex === 2 && <Cart />}
                    {activeIndex === 3 && <Mine />}
                    <nav>
                        {
                            this.state.navList.map((item, index) => {
                                return <div key={index} onClick={() => {
                                    this.setState({
                                        activeIndex: index
                                    })
                                }} className={activeIndex === index ? 'red' : ''}>{item}</div>
                            })
                        }
                    </nav>
                </div>
            )
        }
    }
    class Home extends React.Component {
        render() {
            return (
                <div>
                    <NavBar>
                        <div>#</div>
                        <div>首页</div>
                        <div>*</div>
                    </NavBar>
                </div>
            )
        }
    }
    class Cate extends React.Component {
        render() {
            return (

                <NavBar>
                    <div>分类</div>
                    <div>{false}</div>
                    <div>@</div>
                </NavBar>

            )
        }
    }
    class Cart extends React.Component {
        render() {
            return (

                <NavBar>
                    <div>{'<'}</div>
                    <div>购物车</div>
                    <div>{false}</div>
                </NavBar>

            )
        }
    }
    class Mine extends React.Component {
        render() {
            return (

                <NavBar>
                    <div>{'<'}</div>
                    <div>我的</div>
                    <div>{false}</div>
                </NavBar>

            )
        }
    }
    class NavBar extends React.Component {
        state = {

        }
        render() {
            console.log(this.props);
            return (
                <div className='navbar'>
                    <div className='left'>
                        {
                            this.props.children[0]
                        }
                    </div>
                    <div className='center'>
                        {
                            this.props.children[1]
                        }
                    </div>
                    <div className='right'>
                        {
                            this.props.children[2]
                        }
                    </div>
                </div>
            )
        }
    }

    ReactDOM.render(<App />, document.getElementById('root'))
</script>

</html>